from django.db import models


# Create your models here.
# #创建表
# '''每次创建完表都要执行一下
#     python manage.py makemigrations
#     python manage.py migrate
#     添加数据
#     表名(类名).objects.create(内容)
#     删除数据
#     表名(类名).objects.filter(筛选条件).delete()
#     表名(类名).objects.all().delete()#删除所有
#
#
# '''
# # class UserInfo(models.Model):
# #
# #     name = models.CharField(max_length=32)
# #     password = models.CharField(max_length=64)
# #     age = models.IntegerField()
# #     objects = models.Manager()
#
# '''
# 相当于上述的创建表
# creat table app01_userinfo(
#     id bigint auto_increment primary key,#默认生成的
#     name varchar(32),
#     password varchar(64)
#     age int
# )
# '''

class Department(models.Model):
    objects = models.Manager()

    '''部门表'''
    title = models.CharField(verbose_name='标题', max_length=32)

    def __str__(self):
        return self.title


class UserInfo(models.Model):
    objects = models.Manager()
    '''员工表'''
    name = models.CharField(max_length=16, verbose_name='姓名')
    password = models.CharField(max_length=64, verbose_name='密码')
    age = models.IntegerField(verbose_name='年龄')
    account = models.DecimalField(max_digits=10, decimal_places=2, default=0, verbose_name='账户余额')
    create_time = models.DateField(verbose_name='入职时间')
    # 有约束 -to 与那张表关联  -to_field 与表的那一列关联
    depart = models.ForeignKey(verbose_name='部门', to='Department', to_field='id', on_delete=models.CASCADE)  # 级联删除
    # depart = models.ForeignKey(to='Department',to_field='id',null=True,blank=True,on_delete=models.SET_NULL)#置空
    gender_choices = (
        (1, '男'),
        (2, '女'),
    )
    gender = models.SmallIntegerField(choices=gender_choices, verbose_name='性别')


###############################
class PrettyNum(models.Model):
    objects = models.Manager()
    '''靓号表'''
    mobile = models.CharField(verbose_name='手机号', max_length=11)
    price = models.IntegerField(verbose_name='价格', default=0)
    level_choices = (
        (1, '1级'),
        (2, '2级'),
        (3, '3级'),
        (4, '4级'),
    )
    level = models.SmallIntegerField(verbose_name='等级', choices=level_choices, default=1)
    status_choices = (
        (1, '已占用'),
        (2, '未占用'),
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_choices, default=2)
